<template>
	<view class="padding">

		<view class="text-white padding bg radius">
			<u-form :model="form" ref="uForm" label-position="top" :label-style='lableStyle'>
				<u-form-item label="发布标题">
					<u-input v-model="form.myLevel" placeholder="请填写（必填）" maxlength="50" />
				</u-form-item>
				<!-- <u-form-item label="服务地区">
					<u-input v-model="form.region" :disabled="true" placeholder="请填写 (必填)" @click="goSelectCity()" />
				</u-form-item> -->
				<u-form-item label="服务方式">
					<radio-group @change="wayChange" style="display: flex;">
						<view class="uni-list-cell uni-list-cell-pd" style="display: flex;">
							<view>
								<radio value="1" :checked="form.serviceMethod === '1'" />
							</view>
							<view style="margin-left: 10rpx;">上门服务</view>
						</view>

						<view class="uni-list-cell uni-list-cell-pd" style="display: flex;margin-left: 10rpx;">
							<view>
								<radio value="2" :checked="form.serviceMethod === '2'" />
							</view>
							<view style="margin-left: 10rpx;">到店服务</view>
						</view>
					</radio-group>
				</u-form-item>
				<u-form-item label="区域限制">
					<radio-group @change="restrictChange" style="display: flex;">
						<view class="uni-list-cell uni-list-cell-pd" style="display: flex;">
							<view>
								<radio value="1" :checked="form.regionalRestriction === 1" />
							</view>
							<view style="margin-left: 10rpx;">开启</view>
						</view>

						<view class="uni-list-cell uni-list-cell-pd" style="display: flex;margin-left: 10rpx;">
							<view>
								<radio value="0" :checked="form.regionalRestriction === 0" />
							</view>
							<view style="margin-left: 10rpx;">关闭</view>
						</view>
					</radio-group>
				</u-form-item>
				<u-form-item label="限制区域">
					<button @click="editArea">编辑</button>
				</u-form-item>

				<u-form-item label="服务分类">
					<!-- <u-input v-model="form.game" disabled placeholder="可商议" @click="show = true" /> -->
					<view v-if="game == ''" @click="show = true">
						选择服务分类
					</view>
					<view v-else style="display: inline-flex;" @click="show = true">
						<view v-for="(item,index) in game"
							style="background: #557EFD;margin-right: 15rpx;color: #FFFFFF;padding: 0rpx 15rpx;border-radius: 15rpx;">
							{{item.name}}
						</view>
					</view>
				</u-form-item>
				<u-form-item label="最初的定价">
					<u-input v-model="form.oldMoney" type="number" placeholder="请输入10000元以内（必填）" maxlength="5" />
				</u-form-item>
				<u-form-item label="实际销售价格">
					<u-input v-model="form.money" type="number" placeholder="请输入10000元以内（必填）" maxlength="5" />
				</u-form-item>
				<u-form-item label="最低时间限制">
					<u-input v-model="form.minNum" :disabled="true" type="number" placeholder="请填写（必填）"
						@click="showData = true" />
				</u-form-item>
				<u-form-item label="接单单位">
					<u-radio-group v-model="form.unit" @change="jiedanChange">
						<u-radio shape="circle" active-color="#557EFD" v-for="(item, index) in jiedanList" :key="index"
							:name="item.name">
							{{ item.name }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
			</u-form>
		</view>

		<view>
			<!-- 限制区域弹窗 -->
			<uni-popup ref="popup" background-color="#fff">

				<view class="card">
					<hy-address-multiple v-model="selectData" :nodeData="nodeData"
						:checkOnClickNode="!!checkOnClickNode" :clickCheckPithNode="!!clickCheckPithNode"
						:columnStyle="`height:${selectHeight}vh;flex: 1;background-color:white`" :props="{
									label:'name',
									value:'code',
									children:'children'
								}">
					</hy-address-multiple>
				</view>

			</uni-popup>
		</view>

		<view class="text-white padding bg radius margin-tb">
			<view class="text-lg">上传主页图</view>
			<view class="margin-top"
				style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
				<view style="text-align: center;margin: 80rpx auto 0;" @click="addImage(1)" v-if="!form.homepageImg">
					<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
					<view class="text-sm text-gray margin-top-sm">添加图片(可添加技能图/个人照片)</view>
				</view>
				<image @click="addImage(1)" v-else :src="form.homepageImg" style="width: 100%;height: 320rpx;"></image>
			</view>
		</view>

		<view class="text-white padding bg radius margin-tb">
			<view class="text-lg">上传副图</view>
			<view class="flex flex-wrap margin-top">
				<view v-if="form.altImages.length">
					<view class="flex margin-right-sm flex-wrap">
						<view class="flex" style="width: 200rpx;height: 200rpx;margin-right: 5rpx;position: relative;"
							v-for="(image,index) in form.altImages" :key="index">
							<image :src="image" style="width: 100%;height: 100%;"></image>
							<view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
								@click="removeAltImg(index)">
								<u-icon name="close-circle-fill" color="#2979ff" size="50rpx"></u-icon>
							</view>
						</view>
					</view>
				</view>
				<view class="flex align-center justify-center padding-tb " v-if="form.altImages.length<=3"
					style="background: #f5f5f5;width: 200rpx;height: 200rpx;">
					<view class="text-center" @click="addAltImage(1)">
						<image src="../static/photo.png" style="width:60upx;height: 50upx;"></image>
						<view class="text-sm">上传照片</view>
					</view>
				</view>
			</view>
		</view>

		<view class="text-white padding bg radius margin-tb">
			<view class="text-lg">上传视频</view>
			<view class="margin-top"
				style="border: 2rpx dashed #484B74; width: 100%;height: 320rpx;position: relative;">
				<view style="text-align: center;margin: 80rpx auto 0;" @click="addVideo" v-if="!form.video">
					<image src="../static/photo.png" mode="widthFix" style="width: 73rpx;"></image>
					<view class="text-sm text-gray margin-top-sm">添加视频(可添加技能视频/个人视频)</view>
				</view>
				<!-- <image @click="addImage(1)" v-else :src="form.video" style="width: 100%;height: 320rpx;"></image> -->
				<video v-else :src="form.video" style="width: 100%;height: 320rpx;"></video>
			</view>
		</view>

		<view class="text-white padding bg radius margin-tb">
			<view class="text-lg">上传详情图</view>

			<view class="" style="width: 100%;min-height: 500rpx;">
				<!-- <maxiongEditor v-if="true" :value="Imgo" placeholder="请输入商品详情" @editorChange="editorChange" /> -->
				<maxiongEditor v-if="showEdit" :value="Imgo" placeholder="请输入商品详情" @editorChange="editorChange" />
			</view>

			<!-- <view class="flex" style="overflow: hidden;flex-direction: initial;flex-wrap: wrap;">
				<view v-if="Imgo.length">
					<view class="margin-top flex margin-right-sm flex-wrap">
						<view class="flex" style="width: 200rpx;height: 200rpx;margin-right: 5rpx;position: relative;"
							v-for="(image,index) in Imgo" :key="index">
							<image :src="image" style="width: 100%;height: 100%;"></image>
							<view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
								@click="removeImg(index)">
								<u-icon name="close-circle-fill" color="#2979ff" size="50rpx"></u-icon>
							</view>

						</view>
					</view>
				</view>
				<view class="margin-top" @click="addImages(2)" v-if="Imgo.length<=5">
					<view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
						class="flex justify-center align-center">
						<view>
							<view class="text-center">
								<u-icon name="plus" color="#666666" size="28"></u-icon>
							</view>
							<view class="text-center">选择图片</view>
						</view>
					</view>
				</view>

			</view> -->
		</view>

		<!-- <u-select v-model="show" mode="single-column" :list="gameList" @confirm="selConfirm"></u-select> -->
		<u-popup v-model="show" mode="bottom" border-radius="14" :closeable="true">
			<view class="padding-lr">
				<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="0">
					<view class="scroll-view-item_H" v-for="(ite,ind) in gameYiji" :key="ind"
						:class="ind==titleIndex?'act':''" @click="tabInd(ind,ite)">
						{{ite.gameName}}
					</view>
				</scroll-view>
				<view style="padding: 30rpx 00rpx;">
					<view v-if="gameList.length!=0">
						<u-checkbox-group @change="checkboxGroupChange" size="38" max="3">
							<u-checkbox @change="checkboxChange" v-model="item.checked"
								v-for="(item, index) in gameList" :key="index" :name="item.gameName" :ids="item.id"
								active-color="#557EFD">{{item.gameName}}</u-checkbox>
						</u-checkbox-group>
					</view>
					<view v-else>暂无分类</view>
					<u-button @click="bindGame()" :custom-style="customStyle1">确定</u-button>
				</view>

			</view>
		</u-popup>

		<u-picker v-model="isShowTime" mode="time" zIndex='999999' :params="params" @confirm="statusChange"></u-picker>
		<u-picker v-model="isEndTime" mode="time" zIndex='999999' :params="params" @confirm="endChange"></u-picker>

		<u-button v-if="id" @click="update" class="margin-top" :custom-style="customStyle" shape="circle"
			:hair-line="false">发布</u-button>
		<u-button v-else @click="submit" class="margin-top" :custom-style="customStyle" shape="circle"
			:hair-line="false">发布</u-button>

		<!-- 地区选择 -->
		<!-- <u-picker v-model="Dqshow" mode="region" @confirm="bindRegion"></u-picker> -->

		<!-- <u-action-sheet :list="actionSheetList" v-model="actionSheetShow" @click="actionSheetCallback"></u-action-sheet> -->
		<u-select v-model="showData" mode="mutil-column" :list="listDta" @confirm="confirm"></u-select>
	</view>
</template>

<script>
	import configdata from '@/common/config.js';
	import jsfunRecord from '../components/jc-record/jc-record.vue'
	import maxiongEditor from '@/components/maxiong-editor/maxiong-editor.vue'
	import address from '@/utils/area.js'
	export default {
		components: {
			maxiongEditor,
			jsfunRecord
		},
		data() {
			return {
				showEdit: false,
				time: '',
				startTime: '开始时间（必填）',
				startHour: '',
				endTime: '结束时间（必填）',
				endHour: '',

				isShowTime: false,
				isEndTime: false,
				params: {
					year: false,
					month: false,
					day: false,
					hour: true,
					minute: true,
				},
				form: {
					authentication: 1,
					// game: '',
					gameId: '',
					orderTakingTime: '',
					orderTakingArea: '',
					oldMoney: '',
					money: '',
					voiceIntroduce: '',
					sec: 0,
					homepageImg: '',
					detailsImg: [],
					longitude: '',
					latitude: '',
					city: '',
					id: 0,
					unit: '小时',
					myLevel: '',
					minNum: '',
					region: '',
					detailadd: '',
					twoGame: '',
					orderLevel: '',
					serviceMethod: '',
					regionalRestriction: '',
					restrictedArea: undefined,
					video: '',
					altImage: '',
					altImages: [],
				},
				radioList: [{
					name: '用户已认证',
					checked: true,
					disabled: false,
					val: 1
				}, {
					name: '企业已认证',
					checked: true,
					disabled: false,
					val: 2
				}],
				disabled: false,
				jiedanList: [{
					name: '小时',
					checked: true,
					disabled: 1
				}, {
					name: '天',
					checked: false,
					disabled: 2
				}],
				lableStyle: {
					// color: '#FFFFFF',
					fontSize: '32rpx'
				},
				customStyle: {
					backgroundColor: '#557EFD',
					color: '#FFFFFF',
					border: 0
				},
				status: 1,
				customStyle1: {
					color: '#FFFFFF',
					// position: "fixed",
					// bottom: "30rpx",
					// left: "0rpx",
					// right: "0rpx",
					margin: "30rpx 0rpx"
				},
				showData: false,
				listDta: [
					[{
							value: '1',
							label: '1'
						},
						{
							value: '2',
							label: '2'
						},
						{
							value: '3',
							label: '3'
						},
						{
							value: '4',
							label: '4'
						},
						{
							value: '5',
							label: '5'
						},
						{
							value: '6',
							label: '6'
						},
						{
							value: '7',
							label: '7'
						},
						{
							value: '8',
							label: '8'
						},
						{
							value: '9',
							label: '9'
						},
						{
							value: '10',
							label: '10'
						}
					]
				],
				//录音相关参数
				// #ifndef H5
				//H5不能录音
				RECORDER: uni.getRecorderManager(),
				// #endif

				recording: false,
				willStop: false,

				recordLength: 0, //录音时长

				show: false,
				gameList: [],
				listgame: '',

				game: '',
				checked: false,
				// disabled: true,
				gameYiji: [],
				titleIndex: 0,

				number: 0,
				homepageImg: '',
				id: '',
				isPlay: false,

				Imgo: '',

				isAuthentication: 0,
				Dqshow: false,
				// region: ''

				// 限制区域相关变量
				nodeData: Object.freeze(address.data),
				value: [],
				selectHeight: 50,
				checkOnClickNode: false,
				clickCheckPithNode: false,
				selectData: []
			}
		},
		onLoad(option) {
			// console.log(option.city)
			this.id = option.id
			this.form.id = option.id
			if (this.id) {
				this.getData(this.id)
			} else {
				this.getGameList(0)
				this.showEdit = true;
			}
			this.form.city = uni.getStorageSync('city')
			// this.form.latitude = uni.getStorageSync('latitude')
			// this.form.longitude = uni.getStorageSync('longitude')

			this.isAuthentication = uni.getStorageSync('isAuthentication')
			if (this.isAuthentication == 1) {
				this.radioList[1].disabled = true
			} else if (this.isAuthentication == 2) {
				this.radioList[0].disabled = true
			}

		},
		onShow() {
			//接单单位
			this.$Request.getT('/app/common/type/615').then(res => {
				if (res.code == 0) {
					if (res.data && res.data.value) {
						let danwei = res.data.value.split(',')
						let arr = []
						for (var i = 0; i < danwei.length; i++) {
							let data = {
								name: '',
								checked: false,
								disabled: i
							}
							data.name = danwei[i]
							console.log(danwei[i])
							arr.push(data)
						}
						// console.log(arr)
						this.jiedanList = arr

					}
				}
			});
		},
		methods: {
			queryCitiesByDistrictCodes(districtCodes, regions) {
				// 初始化结果字符串
				let result = '';

				// 遍历省市区数据
				regions.forEach(province => {
					// 初始化省份结果
					let provinceResult = '';
					// 遍历市
					province.children.forEach(city => {
						// 初始化城市结果，并计算城市下区的总数和匹配的区数
						let cityResult = '';
						let totalDistricts = city.children.length;
						let matchedDistricts = 0;

						// 遍历区
						city.children.forEach(district => {
							// 如果区code在提供的集合中，则添加到城市结果中，并增加匹配的区数
							if (districtCodes.includes(district.code)) {
								cityResult += (cityResult ? '，' : '') + district.name;
								matchedDistricts++;
							}
						});

						// 如果城市中的所有区都被匹配，则输出“全部范围”，否则输出匹配的区
						if (matchedDistricts === totalDistricts) {
							provinceResult += (provinceResult ? '，' : '') + city.name + '(全部范围)';
						} else if (matchedDistricts > 0) {
							provinceResult += (provinceResult ? '，' : '') + city.name + '(' + cityResult +
								')';
						}
					});

					// 如果省份中有匹配的城市，则添加到最终结果中
					if (provinceResult) {
						result += (result ? '和' : '') + province.name + '[' + provinceResult + ']';
					}
				});

				return result;

			},
			editArea() {
				this.$refs.popup.open('bottom')
			},
			// 是否开启区域限制
			restrictChange(e) {
				this.form.regionalRestriction = e.detail.value;
				if (e.detail.value === "1") {
					this.$refs.popup.open('bottom')
				}
			},

			// 服务方式改变
			wayChange(e) {
				this.form.serviceMethod = e.detail.value;
			},


			//富文本编辑器内容回调
			editorChange(e) {
				console.log(e)
				this.Imgo = e
			},
			tabInd(index, item) {
				this.listgame = ''
				this.titleIndex = index
				this.form.orderLevel = item.id
				let gameList = this.gameYiji[index]
				var arr = []
				gameList.children.forEach(res => {
					let data = {}
					data.gameName = res.gameName
					data.id = res.id
					data.checked = false
					arr.push(data)
				})
				this.gameList = arr
			},
			//获取省市区
			city(latitude, longitude) {
				this.$Request.get("/app/Login/selectCity", {
					lat: latitude,
					lng: longitude
				}).then(res => {
					this.form.region = res.data.city
				});
			},
			//地区选择
			goSelectCity() {
				let that = this
				uni.chooseLocation({
					success: function(res) {
						// console.log('位置名称：' + res.name);
						// console.log('详细地址：' + res.address);
						// console.log('纬度：' + res.latitude);
						// console.log('经度：' + res.longitude);
						that.form.latitude = res.latitude
						that.form.longitude = res.longitude
						that.form.detailadd = res.address + res.name
						that.city(res.latitude, res.longitude)
					}
				});
			},
			confirm(e) {
				this.form.minNum = e[0].value
			},
			// 详情图删除
			removeImg(index) {
				this.Imgo.splice(index, 1)
			},
			// 选中某个复选框时，由checkbox时触发
			checkboxChange(e) {
				// 	this.checked = e
				// 	this.listgame = e
			},
			// 选中任一checkbox时，由checkbox-group触发
			checkboxGroupChange(e) {
				this.listgame = e

			},
			// 复选框选中提交
			bindGame() {
				this.game = this.listgame
				// console.log(this.listgame)
				let gameId = "";
				let twoGame = ""
				for (var i = 0; i < this.listgame.length; i++) {
					if (i == 0) {
						gameId = this.listgame[i].name
						twoGame = this.listgame[i].id
					} else {
						gameId = gameId + "," + this.listgame[i].name
						twoGame = twoGame + "," + this.listgame[i].id
					}
				}

				this.form.gameId = gameId
				this.form.twoGame = twoGame
				// console.log('获取分类', this.form.twoGame)
				this.show = false
			},
			// radio选择发生变化
			radioGroupChange(e) {
				this.form.classify = e;
			},
			jiedanChange(e) {
				this.form.unit = e;
			},
			saveRecord(recordPath) {
				// console.log("===音频文件地址：" + recordPath + "===")
				uni.showLoading({
					title: '录音上传中...'
				})
				// console.log(this.config("APIHOST1") + '/alioss/uploadMusic')
				uni.uploadFile({
					// url: this.config("APIHOST1") + '/alioss/uploadMusic', //仅为示例，非真实的接口地址
					url: this.config("https://jiazhengshopv5.xianmaxiong.com") + '/alioss/uploadMusic',
					filePath: recordPath,
					name: 'file',
					success: (uploadFileRes) => {
						// console.log(JSON.parse(uploadFileRes.data))
						this.form.voiceIntroduce = JSON.parse(uploadFileRes.data).data.url
						this.form.sec = JSON.parse(uploadFileRes.data).data.sec
						this.recordLength = JSON.parse(uploadFileRes.data).data.sec
						uni.hideLoading()
					},
					fail: (err) => {
						console.log(err)
						uni.hideLoading()
					}
				});
			},
			select(e) {
				this.status = e
			},
			statusChange(e) {
				this.startHour = e.hour
				this.startTime = e.hour + ':' + e.minute
			},
			endChange(e) {
				if (this.startHour >= e.hour) {
					uni.showToast({
						title: '结束时间必须大于开始时间一个小时以上',
						icon: "none"
					})
					return
				}
				this.endTime = e.hour + ':' + e.minute
				this.form.orderTakingTime = this.startTime + '~' + this.endTime
			},
			// 图片上传
			addImages(e) {
				let that = this
				uni.chooseImage({
					count: 6,
					sourceType: ['album', 'camera'],
					success: res => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.$queue.showLoading("上传中...");
							uni.uploadFile({ // 上传接口
								// url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址
								url: 'https://jiazhengshopv5.xianmaxiong.com/sqx_fast/alioss/upload',
								filePath: res.tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									if (e == 2) {
										// console.log(JSON.parse(uploadFileRes.data).data)
										that.Imgo.push(JSON.parse(uploadFileRes.data).data)
									}
									console.log(that.form.detailsImg)
									uni.hideLoading();
								}
							});
						}
					}
				})
			},
			// 图片上传
			addImage(e) {
				uni.previewImage()
				let that = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: res => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.$queue.showLoading("上传中...");
							uni.uploadFile({ // 上传接口
								// url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址
								url: 'https://jiazhengshopv5.xianmaxiong.com/sqx_fast/alioss/upload',
								filePath: res.tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									if (e == 1) {
										that.form.homepageImg = JSON.parse(uploadFileRes.data).data
									}

									uni.hideLoading();
								}
							});
						}
					}
				})
			},
			// 上传副图
			addAltImage() {
				let that = this
				uni.chooseImage({
					count: 3,
					sourceType: ['album', 'camera'],
					success: res => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.$queue.showLoading("上传中...");
							uni.uploadFile({ // 上传接口
								// url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址
								url: 'https://jiazhengshopv5.xianmaxiong.com/sqx_fast/alioss/upload',
								filePath: res.tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									// that.form.homepageImg = JSON.parse(uploadFileRes.data).data
									if (that.form.altImage.length === 0) {
										that.form.altImages = [];
										that.form.altImage = '';
									}
									that.form.altImages.push(JSON.parse(uploadFileRes.data).data);
									that.form.altImage = that.form.altImages.join(',');
									console.log(that.form.altImage);
									uni.hideLoading();
								}
							});
						}
					}
				})
			},
			removeAltImg(index) {
				this.form.altImages.splice(index, 1)
				this.form.altImage = this.form.altImages.join(',');
			},
			// 上传视频
			addVideo() {
				let that = this
				uni.chooseVideo({
					count: 3,
					sourceType: ['album', 'camera'],
					success: res => {
						that.$queue.showLoading("上传中...");
						// console.log(res.tempFilePath)
						uni.uploadFile({ // 上传接口
							// url: this.config("APIHOST1") + '/alioss/upload', //真实的接口地址
							url: 'https://jiazhengshopv5.xianmaxiong.com/sqx_fast/alioss/upload',
							filePath: res.tempFilePath,
							name: 'file',
							success: (uploadFileRes) => {
								that.form.video = JSON.parse(uploadFileRes.data).data;
								uni.hideLoading();
							}
						});
					}
				})
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},
			// 发布
			submit() {
				this.form.detailsImg = this.Imgo
				this.form.detailsImg = this.form.detailsImg;
				this.form.restrictedArea = JSON.stringify(this.selectData);
				if (!this.form.serviceMethod) {
					uni.showToast({
						title: '服务方式不能为空',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (!this.form.regionalRestriction) {
					uni.showToast({
						title: '区域限制不能为空',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (this.form.regionalRestriction === '1' && !this.form.restrictedArea) {
					uni.showToast({
						title: '限制区域不能为空',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (!this.form.myLevel) {
					uni.showToast({
						title: '请填写发布标题',
						icon: 'none',
						duration: 1000
					})
					return
				}
				// if (!this.form.region) {
				// 	uni.showToast({
				// 		title: '请填写服务地区 ',
				// 		icon: 'none',
				// 		duration: 1000
				// 	})
				// 	return
				// }
				if (this.game == '') {
					uni.showToast({
						title: '请选择发布分类',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.oldMoney) {
					uni.showToast({
						title: '请填写最初的定价',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (Number(this.form.oldMoney) > 10000) {
					uni.showToast({
						title: '最初的定价不能大于10000',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (Number(this.form.oldMoney) <= 0) {
					uni.showToast({
						title: '最初的定价不能小于0',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.money) {
					uni.showToast({
						title: '请填写实际销售价格',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (Number(this.form.money) > 10000) {
					uni.showToast({
						title: '实际销售价格不能大于10000',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (Number(this.form.money) <= 0) {
					uni.showToast({
						title: '实际销售价格不能小于0',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.minNum) {
					uni.showToast({
						title: '请填写时间范围',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.homepageImg) {
					uni.showToast({
						title: '请上传主页图',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.detailsImg) {
					uni.showToast({
						title: '请上传详情图',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.altImage) {
					uni.showToast({
						title: '请上传副图',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.video) {
					uni.showToast({
						title: '请上传视频',
						icon: 'none',
						duration: 1000
					})
					return
				}
				this.form.id = ''
				this.$Request.postJson("/app/orderTaking/insertOrderTaking", this.form).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack()
						}, 1000)
					} else if (res.code == 508) {
						uni.showModal({
							title: '提示',
							content: '您还未缴纳保证金，请先去缴纳保证金',
							success: function(re) {
								if (re.confirm) {
									uni.navigateTo({
										url: '/my/wallet/baozhengjin'
									})
								}
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				});
			},
			// 重新编辑
			update() {
				this.form.detailsImg = this.Imgo
				this.form.detailsImg = this.form.detailsImg;
				this.form.restrictedArea = JSON.stringify(this.selectData);

				if (!this.form.serviceMethod) {
					uni.showToast({
						title: '服务方式不能为空',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (!this.form.regionalRestriction) {
					uni.showToast({
						title: '区域限制不能为空',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (this.form.regionalRestriction === '1' && !this.form.restrictedArea) {
					uni.showToast({
						title: '限制区域不能为空',
						icon: 'none',
						duration: 1000
					})
					return
				}

				if (!this.form.myLevel) {
					uni.showToast({
						title: '请填写发布标题',
						icon: 'none',
						duration: 1000
					})
					return
				}
				// if (!this.form.region) {
				// 	uni.showToast({
				// 		title: '请填写服务地区 ',
				// 		icon: 'none',
				// 		duration: 1000
				// 	})
				// 	return
				// }
				if (this.game == '') {
					uni.showToast({
						title: '请选择发布分类',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.oldMoney) {
					uni.showToast({
						title: '请填写最初的定价',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (Number(this.form.oldMoney) > 10000) {
					uni.showToast({
						title: '最初的定价不能大于10000',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.money) {
					uni.showToast({
						title: '请填写实际销售价格',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (Number(this.form.money) > 10000) {
					uni.showToast({
						title: '实际销售价格不能大于10000',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.minNum) {
					uni.showToast({
						title: '请填写时间范围',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.homepageImg) {
					uni.showToast({
						title: '请上传主页图',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.detailsImg) {
					uni.showToast({
						title: '请上传详情图',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.altImage) {
					uni.showToast({
						title: '请上传副图',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.form.video) {
					uni.showToast({
						title: '请上传视频',
						icon: 'none',
						duration: 1000
					})
					return
				}
				
				this.$Request.postJson("/app/orderTaking/updateTakingOrder", this.form).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '编辑成功',
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack()
						}, 1000)
					} else if (res.code == 508) {
						uni.showModal({
							title: '提示',
							content: '您还未缴纳保证金，请先去缴纳保证金',
							success: function(re) {
								if (re.confirm) {
									uni.navigateTo({
										url: '/my/wallet/baozhengjin'
									})
								}
							}
						})
					}
				});
			},
			// 获取游戏列表
			getGameList(index) {
				this.$Request.get("/app/appGame/selectClassifyList").then(res => {
					if (res.code == 0) {
						this.gameYiji = res.data
						this.form.orderLevel = res.data[0].id
						for (var i = 0; i < res.data.length; i++) {
							// debugger;
							if (parseInt(res.data[i].id) == parseInt(index)) {
								this.titleIndex = i
								this.form.orderLevel = index
							}
						}

						let gameList = this.gameYiji[this.titleIndex]

						var arr = []
						gameList.children.forEach(res => {
							let data = {}
							data.gameName = res.gameName
							data.id = res.id
							data.checked = false
							arr.push(data)
						})
						this.gameList = arr
						// console.log('gameListgameList',this.gameList)
						let twoGame = this.form.twoGame.split(',')
						// console.log(this.form.twoGame)
						for (var a = 0; a < twoGame.length; a++) {
							for (var i = 0; i < this.gameList.length; i++) {
								// console.log(this.gameList[i].id, twoGame[a])
								if (this.gameList[i].id == twoGame[a]) {
									this.gameList[i].checked = true
								}
							}
						}

					}
				});
			},
			// 选择游戏
			selConfirm(e) {
				// console.log(e);
				this.form.game = e[0].label
				this.form.gameId = e[0].value
			},
			getData(e) {
				let data = {
					id: e
				}
				this.$Request.get("/app/orderTaking/queryTakingOrder", data).then(res => {
					if (res.code == 0 && res.data) {
						if (res.data.gameId) {
							var arr = []
							let data = {}
							if (res.data.gameId) {
								let gameId = res.data.gameId.split(',')
								for (var i = 0; i < gameId.length; i++) {
									data = {
										name: gameId[i],
									}
									arr.push(data)
								}
							}
							this.game = arr
							this.form.gameId = res.data.gameId
							this.form.twoGame = res.data.twoGame
							// console.error(res.data.twoGame)
						}
						this.getGameList(res.data.orderLevel)
						if (res.data.gameId) {
							let dataList = res.data.gameId.split(',')
							let arrlist = []
							for (var i = 0; i < dataList.length; i++) {
								let gamename = {}
								gamename.name = dataList[i]
								arrlist.push(gamename)
							}

							let twoGameList = res.data.twoGame.split(',')
							// console.log('twoGameListtwoGameList', twoGameList)
							for (var i = 0; i < twoGameList.length; i++) {
								arrlist[i].id = twoGameList[i]
							}
							this.listgame = arrlist
						}
						// this.titleIndex = res.data.orderLevel

						// for (var i = 0; i < list.length; i++) {
						// 		// console.log(this.gameList[i] ,twoGame[a],list[i].id == twoGame[a])
						// 		if (list[i].id == twoGame[a]) {
						// 			listgame.name = list[i].gameName
						// 			listgame.checked = true
						// 			listgame.id = list[i].id
						// 			arrlist.push(listgame)
						// 		}
						// 		this.listgame = arrlist

						// this.form.orderLevel = res.data.orderLevel




						this.form.myLevel = res.data.myLevel
						this.form.oldMoney = res.data.oldMoney
						this.form.money = res.data.money
						this.form.unit = res.data.unit
						this.form.homepageImg = res.data.homepageImg ? res.data.homepageImg : ''
						// this.Imgo = res.data.detailsImg.split(',') ? res.data.detailsImg.split(',') : ''
						this.Imgo = res.data.detailsImg;
						// uni.setStorageSync('isAuthentication', res.data.authentication)
						this.form.authentication = res.data.authentication
						this.form.region = res.data.region
						this.form.region = res.data.region
						this.form.minNum = res.data.minNum
						this.form.serviceMethod = res.data.serviceMethod;
						this.form.regionalRestriction = res.data.regionalRestriction;
						this.selectData = JSON.parse(res.data.restrictedArea);
						this.form.restrictedArea = res.data.restrictedArea;

						this.form.latitude = res.data.latitude
						this.form.longitude = res.data.longitude
						this.form.detailadd = res.data.detailadd
						this.showEdit = true;
						
						this.form.altImages = res.data.altImage.split(',');
						this.form.altImage = res.data.altImage;
						this.form.video = res.data.video;

					}
				});
			},
			// 清除录音
			clearAudio() {
				this.status = 1
				this.recordLength = 0
				this.form.voiceIntroduce = ''
			},


		}
	}
</script>

<style scoped lang="scss">
	.bg {
		background-color: #FFFFFF;
	}

	.u-size-default {
		background: #557EFD !important;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
		margin-top: 80rpx;
	}

	.card {
		margin-top: 40rpx;
		padding: 20rpx;
	}


	.scroll-view-item_H {
		display: inline-block;
		width: 22%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 30rpx;
	}

	.act {
		color: #557EFD;
		font-size: 32rpx;
	}

	.video-container {
		position: relative;
	}

	.video-container video {
		width: 100%;
		height: 200rpx;
	}
</style>